<template>
  <div>
      <div class="top">
        <div style="" class="top-img f-left" @click="JumpIndex"></div>
        <div v-if="!isLogin" class="f-right top-rs">
            <a href="javascript:void(0);" v-on:click="JumpLogin">登录</a>
            <a href="javascript:void(0);" v-on:click="JumpREG">注册</a>
        </div>
        <div v-if="isLogin" class="f-right top-rs">
            <a href="javascript:void(0);" v-on:click="JumpMe">我</a>
            <a href="javascript:void(0);" v-on:click="JumpOut">退出</a>
        </div>
      </div>
  </div>
</template>

<script>
export default {
  data () {
      return {
          isLogin:false//是否登录
      }
  },
  created:function () {
      document.title = '我的信息';
      if(g.sid){
          this.isLogin = true;
      }
  },
  methods:{
      //跳转登录页面
      JumpLogin: function(){
          this.$router.push({
              path:'/login'
          });
      },
      //跳转注册页面
      JumpREG: function(){
          alert('还未开发！');
      },
      //跳转到首页
      JumpIndex: function(){
          let pathStr = this.$route.path;
          if(pathStr != '/'){
              this.$router.push({
                  path: '/'
              });
          }
      },
      JumpOut:function(){
          let self = this;
          try {
              delCookie('sid');
              g.sid='';
          } catch (error) {
              alert('退出失败，稍后重试！');
              return false;
          }

          window.location.reload(true);
          
          function delCookie(name){
            let exp = new Date();
            exp.setTime(exp.getTime() - 1);
            let cval=getCookie(name);
            if(cval!=null)document.cookie= name + "="+cval+";expires="+exp.toGMTString();
         }
         function getCookie(name){
            var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
            if(arr=document.cookie.match(reg))
            return unescape(arr[2]);
            else
            return null;
        }
      },
      //个人信息
      JumpMe: function(){
        this.$router.push({
            path:'/myinfo'
        });
      }
  }
}
</script>
<style scoped>
</style>
